/**
*
* @file     GUI_Layer.h
* @author   IMS Systems Lab - ART Team
* @version  V1.1
* @date     09/10/2009
* @brief    Entry point for GUI layer and relative API
* @details
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* THIS SOURCE CODE IS PROTECTED BY A LICENSE.
* FOR MORE INFORMATION PLEASE CAREFULLY READ THE LICENSE AGREEMENT FILE LOCATED
* IN THE ROOT DIRECTORY OF THIS FIRMWARE PACKAGE.
*
* <h2><center>&copy; COPYRIGHT 2009 STMicroelectronics</center></h2>
*
*/

/**
 *  Define to prevent recursive inclusion
*/
#ifndef __GUI_LAYER_H
#define __GUI_LAYER_H

/**
 *  \include
*/

#include "stm32f10x.h"
#include "iNEMO_lib.h"
#include "string.h"
#include "FreeRTOS.h"
#include "task.h"

// Exported variables
extern u32 count_out;
extern u8 buffer_rx[VIRTUAL_COM_PORT_DATA_SIZE];

/**
 * \addtogroup GUI_Layer
 * \{
 */


/**
* @addtogroup FRAME_CONTROL_DEFINE
* @{
*/
#define CTRL_type            0x00 /*!< control frame */
#define DATA_type            0x40 /*!< data frame */
#define ACK_type             0x80 /*!< Ack frame */
#define NACK_type            0xC0 /*!< NACK frame */

#define ACK_req              0x20 /*!< Ack required */
#define ACK_NOTreq           0x00 /*!< NACK required */

#define Last_Frag            0x00 /*!<  Last Fragment */
#define More_Frag            0x10 /*!< More Fragment */

#define Version_1            0x00 /*!< Frame Version */

#define QoS_Normal           0x00 /*!< Data no Ack Last Fragment */
#define Qos_Medium           0x01 /*!< Data with Ack More Fragment */
#define QoS_High             0x02 /*!< Ack no payload */


#define Ctrl_Check(type,ack,frag,vers,QoS) (type | ack | frag | vers | QoS) /*!< macro to build control byte */
#define CTRL_wACK_LF  Ctrl_Check(CTRL_type, ACK_req ,Last_Frag ,Version_1 ,QoS_Normal)  /*!< macro to build control frame with ack , last fragment */
#define CTRL_noACK_LF  Ctrl_Check(CTRL_type, ACK_NOTreq ,Last_Frag ,Version_1 ,QoS_Normal) /*!< macro to build control frame without ack , last fragment */
#define DATA Ctrl_Check(DATA_type, ACK_NOTreq ,Last_Frag ,Version_1 ,QoS_Normal) /*!< macro to build data frame with ack , last fragment */
#define ACK   Ctrl_Check(ACK_type, ACK_NOTreq, Last_Frag ,Version_1 ,QoS_Normal) /*!< macro to build Ack frame */
#define NACK   Ctrl_Check(NACK_type, ACK_NOTreq ,Last_Frag ,Version_1 ,QoS_Normal) /*!< macro to build NACK frame with ack  */
/**
* @}
*/


/**
* @addtogroup ERROR_CODE
* @{
*/

#define  CmdUnsupported     0x01
#define  ValueOutOfRange    0x02
#define  NotExecutable      0x03
#define  WrongSyntax        0x04
#define  iNEMONotConneted   0x05

/**
* @}
*/


/**
* @addtogroup MESSAGE_ID
* @{
*/

/**
* @addtogroup COMMUNICATION_CONTROL_FRAME
* @{
*/

#define iNEMO_Connect                 0x00
#define iNEMO_Disconnect              0x01
#define iNEMO_Reset_Board             0x02
#define iNEMO_Enter_DFU_Mode          0x03
#define iNEMO_Set_Date_Time           0x04
#define iNEMO_Get_Date_Time           0x05
#define iNEMO_Scan_Request            0x06
#define iNEMO_Trace                   0x07
#define iNEMO_Led                     0x08


/**
* @}
*/

/**
* @addtogroup BOARD_INFO_FRAME
* @{
*/


#define iNEMO_Get_Device_Mode         0x10
#define iNEMO_Get_Type_Node           0x11
#define iNEMO_Get_MCU_ID              0x12
#define iNEMO_Get_FW_Version          0x13
#define iNEMO_Get_HW_Version          0x14
#define iNEMO_Identify                0x15
//#define iNEMO_Get_Gyro_FS             0x16
#define iNEMO_Get_AHRS_Library        0x17

/**
* @}
*/

/**
* @addtogroup SENSOR_SETTING_FRAME
* @{
*/

//#define iNEMO_Set_Acc_ODR             0x20
//#define iNEMO_Get_Acc_ODR             0x21
//#define iNEMO_Set_Acc_HPF             0x22
//#define iNEMO_Get_Acc_HPF             0x23
//#define iNEMO_Set_Acc_FS              0x24
//#define iNEMO_Get_Acc_FS              0x25
//#define iNEMO_Restore_Acc_Default     0x26
//
//#define iNEMO_Set_Magn_FS             0x27
//#define iNEMO_Set_Magn_ODR            0x38
//#define iNEMO_Set_Magn_Mode           0x39
//#define iNEMO_Get_Magn_Par            0x28
//#define iNEMO_Restore_Magn_Default    0x29
//
//#define iNEMO_Set_Press_ODR           0x2A
//#define iNEMO_Get_Press_ODR           0x2B
//#define iNEMO_Restore_Press_Default   0x2C
//
//#define iNEMO_Set_Gyro_Offset         0x30
//#define iNEMO_Get_Gyro_Offset         0x31
//#define iNEMO_Set_Acc_Offset          0x32
//#define iNEMO_Get_Acc_Offset          0x33
//#define iNEMO_Set_Magn_Offset         0x34
//#define iNEMO_Get_Magn_Offset         0x35
//#define iNEMO_Set_Press_Offset        0x36
//#define iNEMO_Get_Press_Offset        0x37

/**
* @}
*/


/**
* @addtogroup ACQUISITION_SENSOR_DATA_FRAME
* @{
*/

#define iNEMO_SetOutMode              0x50
#define iNEMO_GetOutMode              0x51
#define iNEMO_Start_Acquisition       0x52
#define iNEMO_Stop_Acquisition        0x53

/**
* @}
*/


/**
* @addtogroup DEMOS_FRAME
* @{
*/
//#define iNEMO_Start_HIC              0x60
//#define iNEMO_Abort_HIC              0x61
//#define iNEMO_Start_Compass          0x62
//#define iNEMO_Stop_Compass           0x63
//#define iNEMO_Set_Altimeter_Zero_Lev 0x64
//#define iNEMO_Start_Altimeter        0x65

/**
* @}
*/

/**
* @}
*/



/**
 * @defgroup GUI_Layer_Define
 * @{
 */

//#define iNEMO_DEVICE_MODE     0x00   /*!< Sensor Mode */
//#define iNEMO_TYPE_NODE       0x01   /*!< Sensor Mode */

//  FREQUENCY ACQUISITION VALUES

#define LOW_FREQUENCY         0x00    /*!< 1 HZ frequency acquisition */
#define MEDIUM_FREQUENCY_1    0x01    /*!< 10 HZ frequency acquisition */
#define MEDIUM_FREQUENCY_2    0x02    /*!< 25 HZ frequency acquisition */
#define HIGH_FREQUENCY        0x03    /*!< 50 HZ frequency acquisition */


// FRAME TYPE form PC



#define iNEMO_FIRMWARE_VERSION	    "iNEMO Firmware_Version_1.5"
#define SIZE_FWversion  strlen(iNEMO_FIRMWARE_VERSION)

#define iNEMO_HARDWARE_VERSION	    "iNEMO Hardware_Version_1"
#define SIZE_HWversion  strlen(iNEMO_HARDWARE_VERSION)

#ifdef iNEMO_AHRS
#define iNEMO_AHRS_LIBRARY	    "iNEMO AHRS ENABLE"
#else
#define iNEMO_AHRS_LIBRARY	    "iNEMO AHRS DISABLE"
#endif
#define SIZE_AHRSlibrary  strlen(iNEMO_AHRS_LIBRARY)


/**
* @brief iNEMO_GYRO_FS give info about gyros full scale (3 byte, one for each axis)
* @details byte order : RollGyroFS; PitchGyroFS ; YawGyroFS
* @code
* Byte strucutre
*     | RFU | RFU | RFU | RFU | GAIN | FS2 | FS1 | FS2|
* RFU bit mandatory set to 0     
*
*           | FS2 | FS1 | FS0 | Full Scale(dps)|          | FS2 | FS1 | FS0 | Full Scale(dps)|
*           -----------------------------------            -----------------------------------
*           |  0  |  0  |  0  |  +/-30         |          |  1  |  0  |  0  |  +/-1000       |
*           -----------------------------------            -----------------------------------
*           |  0  |  0  |  1  |  +/-100        |          |  1  |  0  |  1  |  +/-1500       |
*           -----------------------------------            ----------------------------------- 
*           |  0  |  1  |  0  |  +/-300        |          |  1  |  1  |  0  |  +/-2000       | 
*           -----------------------------------            -----------------------------------
*           |  0  |  1  |  1  |  +/-500        |          |  1  |  1  |  1  |  Forbidden     | 
*           -----------------------------------            -----------------------------------
* @endcode
*/
#define iNEMO_GYRO_FS {0x02, 0x02,0x02}

/**
* @}
*/

/**
* @defgroup GUI_Layer_API
* @{
*/

void Send_Ack(unsigned char frame, u8 length, u8* payload);
void Send_Nack(unsigned char frame, u8 error_code);
void Send_Data(unsigned char frame, u8 length, u8* payload);
//void Set_Timer(unsigned char number);
void ParseGuiFrame(u32 nFrameSize);
void DataProcess(u8 outmode, iNEMO_DATA *pData);

void SetAhrs(bool bEnable);
void SetRawData(bool bEnable);
void SetCalData(bool bEnable);
bool GetAhrs();
bool GetRawData();
bool GetCalData();
void SetOutMode(u8 outmode);
u8 GetOutMode();

/**
 * @}
 */

/**
 * \}
 */
#endif /*__HAL_LAYER_H */

/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
